<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<script src="<%=request.getContextPath()%>/static/js/jQuery/jquery.min.js"></script>
<script src="<%=request.getContextPath()%>/static/js/ajax-fileuploader/ajaxfileupload.js"></script>
<body>
<h2><input value="Hello World!" onclick="queryButton()"/></h2>
<input type="hidden" id="homeBackGround" name="homeBackGround"/>
<input type="file" id = "file">
</body>
<script type='text/javascript'>    
		function queryButton(){
			$.ajax({
		        url : 'http://test.linkedandes.com/admin/companyPolicy/getCompanyPolicyPage',
		        data : {"stage":'2'},
		        dataType: 'json',
		        type : 'POST',
		        xhrFields: {
		            withCredentials: true
		        }, 
		        crossDomain: true,
		        success:function(data){
		        	console.log(data);
		        	if(data.res==301){
		        		window.location="./tt.do";
		        	}
		        }}
			)
		}
		(function(window, undefined) {
	 		var file = $('#file');

	 		file.on('change', uploadFile);

	 		function uploadFile(event) {
	 			var target = event.target || event.srcElement,
	 				_file = target.files[0],
	 				formData = new FormData();

	 			formData.append('file', file[0].files[0]); //将文件转成二进制形式
	 			
	 		//	formData.append('file11', file[0].files[0]); //将文件转成二进制形式
	 			//formData.append('param', 'file11'); 
	 		//	formData.append('preImg', 'file/qqzb/test/201609/1474177841609.jpg');
	 			$.ajax({
					type: "post",
					url: "http://test.linkedandes.com/upload/uploadimg/qqzb/test",
					contentType: false, //这个一定要写
					processData: false, //这个也一定要写，不然会报错
					data: formData,
					dataType: 'json', //返回类型，有json，text，HTML。这里并没有jsonp格式，所以别妄想能用jsonp做跨域了。
					success: function(data) {
						if (data.res == 1) {
							alert(data.result);
							console.log(data.result);
							alert('上传成功');
						} else {
							alert('上传失败');
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown, data) {
							alert('上传失败');
					}
				});

	 		}
	 	})(window);
		
		/**
		 * ajax背景图上传
		 */
		/*  function saveImgtt(){
		 $.ajax({
				type: "post",
				url: "http://test.linkedandes.com/upload/uploadimg/qqzb/test",
				contentType: false, //这个一定要写
				processData: false, //这个也一定要写，不然会报错
				data: formData,
				dataType: 'json', //返回类型，有json，text，HTML。这里并没有jsonp格式，所以别妄想能用jsonp做跨域了。
				success: function(data) {
					if (data.code == 1) {
						_this.hasUpload = true;
						_this.photoUrl = data.url;
						_this.inputBlurHandler();
					} else {

					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown, data) {}
			});
		} */
		/*  function saveImgtt(){
		 	var urlPic="http://test.linkedandes.com/upload/uploadimg/qqzb/test";
		 		$.ajaxFileUpload({
		 			url:urlPic,
		 			secureuri:false,
		 			fileElementId:"imgLogoTu",
		 			dataType:'json',
		 			data:{
		 				preImg:$("#homeBackGround").val(),
		 				param:"imgLogo2"
		 			},
		 			beforeSend:function(){
		 			},
		 			complete:function(){
		 			},				
		 			success: function (data){
		 				alert(data.res);
		 				//上传成功 将图片的路径写入隐藏域
		 				 if(data.res==1){
		 					alert(data.result);
		 					$("#homeBackGround").val(data.result);
		 				}
		 			},
		 			error: function (data, status, e){
		 				console.log(e);
		 				alert("上传失败111");
		 			}
		 		});	
		 	} */
			/* alert("//");
			$.post("http://test.linkedandes.com/admin/companyPolicy/getMaterialById?id=8",{},function(data){
				if(data.res==301){
					//登录态失效 
					$.post("http://test.linkedandes.com/login/toLogin?user_name=test&password=e10adc3949ba59abbe56e057f20f883e",{},function(data){
						console.log(data);
						if(data.res==1){
							alert("成")
						}
					});
				}
			});
		} */
	/* 	var id=8;
		$.ajax({
	        url : 'http://test.linkedandes.com/admin/companyPolicy/getMaterialById',
	        data : id,
	        dataType: 'json',
	        type : 'POST',
	        xhrFields: {
	            withCredentials: true
	        },
	        crossDomain: true,
	        contentType: "application/json",
	        success:function(data){
				if(data.res==301){
					$.ajax({
				        url : 'http://test.linkedandes.com/login/toLogin',
				        data : {"user_name":"test","password":"e10adc3949ba59abbe56e057f20f883e"},
				        dataType: 'json',
				        type : 'POST',
				        xhrFields: {
				            withCredentials: true
				        },
				        crossDomain: true,
				        contentType: "application/json",
				        success:function(data){
				        	alert(data.res);	
				        }
					});
				        }
				}
		}
		); */
    </script>
</html>
